package chapter07;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Test06_playCards {
    public static void main(String[] args) {
        //完成斗地主的发牌
        String[] flowers = {"♠","♥","♣","♦"};
        String[] numbers = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        ArrayList<String> list = new ArrayList<>();
        for(int i=0;i<flowers.length;i++){
            for(int j=0;j<numbers.length;j++){
                list.add(flowers[i]+numbers[j]);
            }
        }
        list.add("大王");
        list.add("小王");
        System.out.println(list);
        //洗牌 随机洗牌
        Collections.shuffle(list);
        System.out.println(list);
        //发牌 三家 一家17张
        List<String> n1 = list.subList(0, 17);
        System.out.println(n1);
        System.out.println(n1.size());
        List<String> n2 = list.subList(17, 34);
        System.out.println(n2);
        System.out.println(n2.size());
        List<String> n3 = list.subList(34, 51);
        System.out.println(n3);
        System.out.println(n3.size());
        List<String> n4 = list.subList(51, list.size());
        System.out.println(n4);
        //自定义规则
        Collections.sort(n1, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Character.compare(o1.toCharArray()[1],o2.toCharArray()[1]);
            }
        });
        System.out.println(n1);
        Collections.sort(n2, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Character.compare(o1.toCharArray()[1],o2.toCharArray()[1]);
            }
        });
        System.out.println(n2);
        Collections.sort(n3, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Character.compare(o1.toCharArray()[1],o2.toCharArray()[1]);
            }
        });
        System.out.println(n3);
    }
}
